//
//  RBGConfigurationClientService.m
//  BateauGenerique
//
//  Created by Kevin De Jesus Ferreira on 21/05/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "RBGConfigurationClientService.h"
#import "RBGNetGet.h"
#import "Constantes.h"
#import "RBGParserDonnees.h"

@interface RBGConfigurationClientService ()<NetGetDelegate,ParserDonneesDelegate>

@end

@implementation RBGConfigurationClientService


-(void) getDonnneesByUrl:(NSString *)url
            andArguments:(NSDictionary *)arguments
{
    
    RBGNetGet * net = [[RBGNetGet alloc]init];
    net.delegate = self;
    [net getDonnees:[self construireUrl:url andArguments:arguments]];
}

-(NSString *) construireUrl:(NSString *)url
         andArguments:(NSDictionary *)arguments
{
    NSMutableString * urlConstruite = [[NSMutableString alloc]init];
    NSArray * keys = [arguments allKeys];
    
    NSString * tmp ;
    
    [urlConstruite appendString:url];

    for(NSString * key in keys)
    {
        tmp = [NSString stringWithFormat:@"%@=%@&",key,[arguments objectForKey:key] ];
        
        
        [urlConstruite appendString:tmp];
    }
    
    
    return  [NSString stringWithString:urlConstruite];
}

-(void) chargerTypesCategories:(BOOL)wa{
    
}

- (void) receiveDonnees:(NSString *)donnees
{
    
    RBGParserDonnees * parser = [[RBGParserDonnees alloc]init];
    parser.delegate = self;
   
    NSLog(donnees);
    
    [parser parserDonnees:[self.typeService integerValue] withDonnees:donnees];
}

- (void) receiveErreur:(int)statut{
    [self.delegate receiveErreurService:statut];
}

- (void) receiveDonneesParser:(id)donnees
{
   [self.delegate receiveDonneesService:donnees fromService:[self.typeService integerValue]];
}

- (void) receiveErreurParsing:(int)statut
{
    [self.delegate receiveErreurService:statut];
}

@end
